﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 算法基本功.算法._0_数组._1_双指针.快慢指针
{
    internal class 删除有序数组中的重复项
    {
        public int RemoveDuplicates(int[] nums)
        {
            if(nums.Length == 0 ) return 0;
            //慢指针负责记录不重复的元素 , 快指针负责遍历数组
            int slow = 0 ,fast = 0;
            while (fast<nums.Length) {
                if (nums[slow] != nums[fast])
                {
                    slow++;
                    nums[slow] = nums[fast];
                }
                fast++;
            }
            return slow + 1;
        }
    }
}
